* Figure A3: Binscatter Plots

clear
use "${data_dir}DavisMazumderData.dta"

keep if age_firstSurvey<=18
drop if miss0 | miss1
drop if (mom_outOfRange==1 & linkMom==1 & !(dad_outOfRange==0 & linkDad==1)) | (dad_outOfRange==1 & linkDad==1 & !(mom_outOfRange==0 & linkMom==1)) | (linkMom==0 & linkDad==0) 
 



* Generate income ranks after applying sample restrictions
gen N = .
 tab n  if surv79==0 & women==0  [w=weight]
 replace N = r(N) if surv79==0 & women==0 
 tab n  if surv79==0 & women==1   [w=weight]
 replace N = r(N) if surv79==0 & women==1 
 tab n  if surv79==1 & women==0   [w=weight]
 replace N = r(N) if surv79==1 & women==0 
 tab n  if surv79==1 & women==1 [w=weight]
 replace N = r(N) if surv79==1 & women==1 
 
* Family Income Rank in Parent Generation
set sortseed 6688571
sort women surv79 faminc0
by women surv79: gen __rank0 = sum(weight) 
gen _rank0 = __rank0/N 
by women surv79 faminc0: egen rank0 = mean(_rank0) 
 replace rank0 = 100*rank0
gen perc66 = rank0*(1-surv79)
gen perc79 = rank0*surv79

 
* Family Income Rank in Kid Generation
set sortseed 6688571
sort women surv79 faminc1
by women surv79: gen __rank1 = sum(weight)
gen _rank1 = __rank1/N 
bys women surv79 faminc1: egen rank1 = mean(_rank1) 
replace rank1 = 100*rank1

drop N __rank0 _rank0 __rank1 _rank1 



binscatter rank1 rank0 [w=weight], by(survey) ///
	legend(label(1 "1948-1953 Cohorts") label(2 "1961-1964 Cohorts")) xtitle("Parent Rank") ytitle("Child Rank") ylabel(25(25)75, nogrid)
graph export ${results_dir}figureA3_rank.png, replace


binscatter lfaminc1 lfaminc0 [w=weight], by(survey) ///
	legend(label(1 "1948-1953 Cohorts") label(2 "1961-1964 Cohorts")) xtitle("Log Family Income, Parent Gen") ytitle("Log Family Income, Child Gen") ylabel(9.5(0.5)12, nogrid)
graph export ${results_dir}figureA3_ige.png, replace



binscatter rank1 rank0 if women==1 [w=weight], by(survey) ///
	legend(label(1 "1948-1953 Cohorts") label(2 "1961-1964 Cohorts")) xtitle("Parent Rank") ytitle("Child Rank") ylabel(25(25)75, nogrid)
graph export ${results_dir}figureA6_rank.png, replace


binscatter lfaminc1 lfaminc0 if women==1 [w=weight], by(survey) ///
	legend(label(1 "1948-1953 Cohorts") label(2 "1961-1964 Cohorts")) xtitle("Log Family Income, Parent Gen") ytitle("Log Family Income, Child Gen") ylabel(9.5(0.5)12, nogrid)
graph export ${results_dir}figureA6_ige.png, replace

binscatter rank1 rank0 if women==0 [w=weight], by(survey) ///
	legend(label(1 "1948-1953 Cohorts") label(2 "1961-1964 Cohorts")) xtitle("Parent Rank") ytitle("Child Rank") ylabel(25(25)75, nogrid)
graph export ${results_dir}figureA7_rank.png, replace


binscatter lfaminc1 lfaminc0 if women==0 [w=weight], by(survey) ///
	legend(label(1 "1948-1953 Cohorts") label(2 "1961-1964 Cohorts")) xtitle("Log Family Income, Parent Gen") ytitle("Log Family Income, Child Gen") ylabel(9.5(0.5)12, nogrid)
graph export ${results_dir}figureA7_ige.png, replace

exit
